/*****************************************************************************
* Keppe Messenger (KMP) Keppe Project-Team User Messaging System
* Copyright (C) 2013-2014 Keppe Project-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

#include "frmProfileInfo.h"
#include "ui_frmProfileInfo.h"
#include <QMessageBox>

frmProfileInfo::frmProfileInfo(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::frmProfileInfo)
{
    setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint);
    ui->setupUi(this);
#ifdef MACX
    this->setMinimumSize(350,400);
    this->setMaximumSize(350,400);
    this->resize(350,400);
#else
#ifdef UNIX
    this->setMinimumSize(350,375);
    this->setMaximumSize(350,375);
    this->resize(350,375);
#endif
#endif
    ui->cmdShowClients->setDisabled(true);
}

frmProfileInfo::~frmProfileInfo()
{
    delete ui;
}

void frmProfileInfo::setUser(QString username)
{
    ui->labName->setText(QApplication::tr("Account: %1").arg(username));
}

void frmProfileInfo::setNick(QString nickname)
{
    nick = nickname;
    ui->labNick->setText(QApplication::tr("Name: %1").arg(nickname));
}

void frmProfileInfo::setContacts(QString contacts)
{
    ui->labContacts->setText(QApplication::tr("Contacts: %1").arg(contacts));
}

void frmProfileInfo::setMessageState(QString message)
{
    ui->labMsgState->setText(QApplication::tr("Status: %1").arg("<span>"+message+"</span>"));
}

void frmProfileInfo::setMaps(QList<QMap<QString, QString> > newMaps)
{
    maps = newMaps;
    if (newMaps.length() >= 1)
    {
        ui->cmdShowClients->setEnabled(true);
    }
    ui->labClients->setText(QApplication::tr("Clients: %1").arg(QString::number(newMaps.length())));
}

void frmProfileInfo::setSignature(QString signatureColor)
{
    if (signatureColor == "Gold")
    {
        ui->labSignature->setText(QApplication::tr("Signature: %1").arg(QApplication::tr("Gold")));
        ui->imgSignature->setMinimumSize(128,128);
        ui->imgSignature->setMaximumSize(128,128);
        ui->imgSignature->setScaledContents(true);
        ui->imgSignature->setPixmap(QPixmap(":/gui/KeppeMessengerAvatarGold.png"));
    }
    else if (signatureColor == "Silver")
    {
        ui->labSignature->setText(QApplication::tr("Signature: %1").arg(QApplication::tr("Silver")));
        ui->imgSignature->setMinimumSize(128,128);
        ui->imgSignature->setMaximumSize(128,128);
        ui->imgSignature->setScaledContents(true);
        ui->imgSignature->setPixmap(QPixmap(":/gui/KeppeMessengerAvatarSilver.png"));
    }
    else if (signatureColor == "Bronze")
    {
        ui->labSignature->setText(QApplication::tr("Signature: %1").arg(QApplication::tr("Bronze")));
        ui->imgSignature->setMinimumSize(128,128);
        ui->imgSignature->setMaximumSize(128,128);
        ui->imgSignature->setScaledContents(true);
        ui->imgSignature->setPixmap(QPixmap(":/gui/KeppeMessengerAvatarBronze.png"));
    }
    else
    {
        ui->labSignature->setText(QApplication::tr("Signature: %1").arg(QApplication::tr("Regular")));
        ui->imgSignature->setMinimumSize(128,128);
        ui->imgSignature->setMaximumSize(128,128);
        ui->imgSignature->setScaledContents(true);
        ui->imgSignature->setPixmap(QPixmap(":/gui/KeppeMessengerAvatar.png"));
    }
}

void frmProfileInfo::on_cmdOkay_clicked()
{
    this->close();
}

void frmProfileInfo::on_cmdShowClients_clicked()
{
    QString message;
    message.append(QApplication::tr("Clients of %1").arg(nick) + "\n");
    int curlen = 0;
    int maxlen = maps.length();
    while (curlen != maxlen)
    {
        bool ht = false;
        QMap<QString,QString> map = maps.at(curlen);
        message.append("\n");
        if (map.contains("system"))
        {
            if (ht)
            {
                message.append(", ");
            }
            else
            {
                ht = true;
            }
            message.append(QApplication::tr("System") + ": " + map["system"]);
        }
        if (map.contains("version"))
        {
            if (ht)
            {
                message.append(", ");
            }
            else
            {
                ht = true;
            }
            message.append(QApplication::tr("Version") + ": " + map["version"]);
        }
        if (map.contains("ip"))
        {
            if (ht)
            {
                message.append(", ");
            }
            else
            {
                ht = true;
            }
            message.append(QApplication::tr("IP") + ": " + map["ip"]);
        }
        curlen++;
    }
    QMessageBox::information(this,QApplication::tr("Clients"),message);
}

void frmProfileInfo::on_bbOK_clicked(QAbstractButton *button)
{
    if (ui->bbOK->buttonRole(button) == QDialogButtonBox::AcceptRole)
    {
        on_cmdOkay_clicked();
    }
}
